mydat = rgdal::readOGR("./new_map/nynta.shp")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/wuxinyao/Desktop/p8105_final_project/new_map/nynta.shp", layer: "nynta"
## with 195 features
## It has 7 fields
mydat2 = rgdal::readOGR("./new_map/nynta.shp")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/wuxinyao/Desktop/p8105_final_project/new_map/nynta.shp", layer: "nynta"
## with 195 features
## It has 7 fields
summary(mydat2)
## Object of class SpatialPolygonsDataFrame
## Coordinates:
## min max
## x 913175.1 1067382.5
## y 120121.9 272844.3
## Is projected: TRUE
## proj4string :
## [+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333
## +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000 +y_0=0
## +datum=NAD83 +units=us-ft +no_defs +ellps=GRS80 +towgs84=0,0,0]
## Data attributes:
## BoroCode BoroName CountyFIPS NTACode
## Min. :1 Bronx :38 005:38 BK09 : 1
## 1st Qu.:2 Brooklyn :51 047:51 BK17 : 1
## Median :3 Manhattan :29 061:29 BK19 : 1
## Mean :3 Queens :58 081:58 BK21 : 1
## 3rd Qu.:4 Staten Island:19 085:19 BK23 : 1
## Max. :5 BK25 : 1
## (Other):189
## NTAName Shape_Leng
## Airport : 1 Min. : 11000
## Allerton-Pelham Gardens : 1 1st Qu.: 23824
## Annadale-Huguenot-Prince's Bay-Eltingville: 1 Median : 30556
## Arden Heights : 1 Mean : 42011
## Astoria : 1 3rd Qu.: 41877
## Auburndale : 1 Max. :490196
## (Other) :189
## Shape_Area
## Min. : 5573902
## 1st Qu.: 19383534
## Median : 32629789
## Mean : 43230288
## 3rd Qu.: 50237450
## Max. :327760045
##
summary(mydat)
## Object of class SpatialPolygonsDataFrame
## Coordinates:
## min max
## x 913175.1 1067382.5
## y 120121.9 272844.3
## Is projected: TRUE
## proj4string :
## [+proj=lcc +lat_1=40.66666666666666 +lat_2=41.03333333333333
## +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000 +y_0=0
## +datum=NAD83 +units=us-ft +no_defs +ellps=GRS80 +towgs84=0,0,0]
## Data attributes:
## BoroCode BoroName CountyFIPS NTACode
## Min. :1 Bronx :38 005:38 BK09 : 1
## 1st Qu.:2 Brooklyn :51 047:51 BK17 : 1
## Median :3 Manhattan :29 061:29 BK19 : 1
## Mean :3 Queens :58 081:58 BK21 : 1
## 3rd Qu.:4 Staten Island:19 085:19 BK23 : 1
## Max. :5 BK25 : 1
## (Other):189
## NTAName Shape_Leng
## Airport : 1 Min. : 11000
## Allerton-Pelham Gardens : 1 1st Qu.: 23824
## Annadale-Huguenot-Prince's Bay-Eltingville: 1 Median : 30556
## Arden Heights : 1 Mean : 42011
## Astoria : 1 3rd Qu.: 41877
## Auburndale : 1 Max. :490196
## (Other) :189
## Shape_Area
## Min. : 5573902
## 1st Qu.: 19383534
## Median : 32629789
## Mean : 43230288
## 3rd Qu.: 50237450
## Max. :327760045
##
proj4string = "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
proj4string1 = "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80
+towgs84=0,0,0"
mydat2 = spTransform(mydat, proj4string1)
bins <- c(0, 50000000, 100000000, 150000000, 200000000, Inf)
pal <- colorBin("YlOrRd", domain = mydat2$Shape_Area, bins = bins)
leaflet() %>%
addProviderTiles("OpenStreetMap.Mapnik") %>%
setView(lat = 40.7, lng = -74, zoom = 9) %>%
addPolygons(data = mydat2, fillColor = ~pal(Shape_Area), weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7)
names(mydat2)
## [1] "BoroCode" "BoroName" "CountyFIPS" "NTACode" "NTAName"
## [6] "Shape_Leng" "Shape_Area"
uk
UK <- getData("GADM", country = "GB", level = 2)
### Create dummy data
set.seed(111)
mydf <- data.frame(place = unique(UK$NAME_2),
value = sample.int(n = 1000000, size = n_distinct(UK$NAME_2), replace = TRUE))
### Create five colors for fill
mypal <- colorQuantile(palette = "RdYlBu", domain = mydf$value, n = 5, reverse = TRUE)
leaflet() %>%
addProviderTiles("OpenStreetMap.Mapnik") %>%
setView(lat = 55, lng = -3, zoom = 6) %>%
addPolygons(data = UK,
stroke = FALSE, smoothFactor = 0.2, fillOpacity = 0.3,
fillColor = ~mypal(mydf$value),
popup = paste("Region: ", UK$NAME_2, "<br>",
"Value: ", mydf$value, "<br>")) %>%
addLegend(position = "bottomright", pal = mypal, values = mydf$value,
title = "UK value",
opacity = 1)